//
//  MBProgressHUD+FD.m
//  FD
//
//  Created by xiaofang wang on 2018/11/10.
//  Copyright © 2018年 ZhiYuan Network. All rights reserved.
//

#import "MBProgressHUD+FD.h"

@implementation MBProgressHUD (FD)

#pragma mark - 一 private
+ (void)showText:(NSString *)text iconStr:(NSString *)icon toView:(UIView *)view
{
    if (view == nil) {
       view = [[UIApplication sharedApplication].windows lastObject];
    }
    
    //创建hud
    MBProgressHUD *hub = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hub.label.text = text;
    
    //设置图片
//    NSString *imgStr = [NSString stringWithFormat:@"MBProgressHUD.bundle/%@",icon];
    hub.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:icon]];
    //设置模式
    hub.mode = MBProgressHUDModeCustomView;
    
    //隐藏式从父控件中移除
    hub.removeFromSuperViewOnHide = YES;
    
    //2.s之后再消失
    [hub hideAnimated:YES afterDelay:2.0];
}

#pragma mark - 二 接口
/**1-1显示菊花*/
+ (MBProgressHUD *)fd_showHUDToView:(UIView *)view
{
    return [self fd_showMessage:@"" toView:view];
}
/**1.显示提示信息*/
+ (MBProgressHUD *)fd_showMessage:(NSString *)msg toView:(UIView *)view
{
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.label.text = msg;

    //影藏时从父视图中移除
    hud.removeFromSuperViewOnHide = YES;

    //是否显示蒙版
//    hud.backgroundColor  = [UIColor redColor];
//    hud.backgroundColor = kMainLightGrayColor;
//    hud. 'dimBackground' is deprecated: Customize(定制) HUD background properties instead.
    
    return hud;
}

/**2.成功提示信息*/
+ (void)fd_showSuccess:(NSString *)success toView:(UIView *)view
{
    [self showText:success iconStr:@"success.png" toView:view];
}

/**4.显示失败信息*/
+ (void)fd_showErrow:(NSString *)errow toView:(UIView *)view {
    [self showText:errow iconStr:@"error.png" toView:view];
}
/**3.影藏菊花*/
+ (void)fd_hideHUDFromView:(UIView *)view
{
    [self hideHUDForView:view animated:YES];
}


@end

